package a_;

import org.junit.Test;

import java.io.*;
import java.util.Date;

public class ObjectStreamDemo {
    @Test
    public void test1() throws IOException {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("objectStream.obj"));

        String str = "你好";
        oos.writeObject(str);

        Date date = new Date();
        oos.writeObject(date);
        oos.writeObject(null);
    }

    @Test
    public void test2() throws IOException, ClassNotFoundException {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("objectStream.obj"));

        String s = (String)ois.readObject();
        System.out.println(s);
        Object o = ois.readObject();
        System.out.println(o);
        Object o1 = ois.readObject();
        System.out.println(o1);
    }
}
